// 页面路径：store/index.js 
// import Vue from 'vue'
import Vuex from 'vuex'

// Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
  state: { //存放状态
    "username": "foo",
    "age": 18,
    "password": '',
    "returnTime": '',
    "rentTime": '',
    // 是否登录
    isLoggedIn: false,
    address: '',
    // 存储管理员信息
    admin: {},
    user: {}, // 存储用户信息
    business: {}, // 存储商家信息
    token: '', //保留token字段
    days: 1, //保存租车天数，默认是1天
    orders: {}, //存储订单数据
  },
  mutations: {
    updateOrders(state, orders) {
      state.orders = orders
    },
    updateDays(state, days) {
      state.days = days
    },
    updateAddress(state, address) {
      state.address = address
    },
    updatetToken(state, token) {
      state.token = token
    },
    updateUser(state, user) {
      // 变更状态
      state.username = user.username
      state.password = user.password
    },
    updateReturnTime(state, time) {
      state.returnTime = time
    },
    updateRentTime(state, time) {
      state.rentTime = time
    },
    // login方法用于将用户信息存储到state中并设置登录状态为true，logout方法用于清空用户信息并将登录状态设置为false
    // login方法用于将用户信息存储到state中并设置登录状态为true，logout方法用于清空用户信息并将登录状态设置为false

    loginUser(state, user) {
      state.isLoggedIn = !state.isLoggedIn
      state.user = user
    },

    loginBusiness(state, business) {
      state.isLoggedIn = true
      state.business = business
    },

    loginAdmin(state, admin) {
      state.isLoggedIn = true
      state.admin = admin
    },



    // logout(state) {
    // 	state.isLoggedIn = false
    // 	state.admin = null
    // },

    // logout(state) {
    //   state.isLoggedIn = false
    //   state.admin = null
    // },
  }
})
export default store